<template>
  <div class="cateLeft">
    <div class="main">
      <div class="top">图书分类</div>
      <el-scrollbar class="scroll" @mouseenter="scrollEnter" @mouseleave="scrollOut">
        <div class="item" v-for="(i, index) in cateLiefList" :key="i.id" @mouseenter="moveEnter(index)">
          <el-space>
            <span class="sp_1" @click="toCate(i.id, i.path)">{{ i.name }}</span>
            <span class="iconfont icon-right"></span>
          </el-space>
        </div>
      </el-scrollbar>
      <!-- is_show && leftOut -->
      <el-scrollbar class="posi_right" v-show="is_show && leftOut" @mouseleave="seleaveOut" @mouseenter="rightEnter">
        <el-row v-for="a in list" :key="a.id" class="item_row">
          <el-col :span="5" style="text-algin: right">
            <span class="coltext_1" @click="toCate(a.id, a.path)">
              {{ a.name }}
            </span>
          </el-col>
          <el-col :span="19" :push="1">
            <!-- spacer="|" -->
            <el-space :wrap="true" :size="4">
              <!-- <template #default>
                <span>1</span>
              </template> -->
              <span v-for="b in a.child" :key="b.id" class="colspan_2" @click="toCate(b.id, b.path)">
                {{ b.name }}
              </span>
            </el-space>
          </el-col>
        </el-row>
      </el-scrollbar>
    </div>
    <!-- </el-scrollbar> -->
  </div>
</template>

<script>
export default {
  name: 'cata-left',
  data() {
    return {
      cateLiefList: [],
      list: [],
      // 控制左侧的显示隐藏
      is_show: false,
      // 是否移入右侧
      leftOut: false,
      // 右侧的高度
      height: 0,
    }
  },
  mounted() {
    this.getLeftCate()
  },
  methods: {
    getLeftCate() {
      this.$http
        .get('category')
        .then((res) => {
          res.data.data.forEach((item) => {
            if (!('child' in item)) {
              item.child = []
            }
            item.child.forEach((ele) => {
              if (!('child' in ele)) {
                ele.child = []
              }
            })
          })
          this.cateLiefList = res.data.data
          this.list = this.cateLiefList[0].child
          console.log(this.cateLiefList)
        })
        .catch((e) => {
          console.log(e.message)
        })
    },
    toCate(id, path) {
      const routeUrl = this.$router.resolve({
        path: '/cate',
        query: { id, path },
      })
      window.open(routeUrl.href, '_blank')
    },
    moveEnter(flog) {
      this.list = this.cateLiefList[flog].child
      this.height = 33 * flog
    },
    // 移入左侧
    scrollEnter() {
      this.is_show = true
      this.leftOut = true
    },
    // 移出左侧
    scrollOut() {
      this.is_show = true
      this.leftOut = false
    },
    // 移入右侧
    rightEnter() {
      this.leftOut = true
    },
    // 移出右侧
    seleaveOut() {
      this.leftOut = false
    },
  },
}
</script>

<style scoped lang="scss">
.cateLeft {
  width: 100%;
  .main {
    border: 1px solid #487a6f;
    border-top-right-radius: 6px;
    border-top-left-radius: 6px;
    width: 190px;
    height: 916px;
    position: relative;
    .top {
      height: 35px;
      color: #fff;
      text-align: center;
      line-height: 35px;
      font-family: 'Microsoft Yahei';
      font-size: 18px;
      background: #487a6f;
      border-bottom: 2px dotted #487a6f;
      box-sizing: border-box;
    }
    .scroll {
      height: 881px;
    }
    .item {
      width: 100%;
      height: 33px;
      padding: 0 6px;
      box-sizing: border-box;
      position: relative;
      // &:hover{
      //   border-bottom: 1px solid #849555;
      // }
      .el-space {
        width: 100%;
        display: flex;
        justify-content: space-between;
        height: 100%;
        box-sizing: border-box;
        border-bottom: 1px dotted #849555;
        cursor: pointer;
        position: relative;
        // &:hover {
        //   border-bottom: none;
        // }
        .sp_1 {
          font-size: 14px;
          color: #487a6f;
          font-family: 'Microsoft Yahei';
          font-weight: bold;
          &:hover {
            color: #ec7814;
          }
        }
        .icon-right {
          font-size: 20px;
        }
      }
    }
    .posi_right {
      position: absolute;
      // height: 400px;
      width: 759px;
      height: 881px;
      left: 191px;
      z-index: 99;
      top: 35px;
      background: #fff;
      padding: 10px;
      box-sizing: border-box;
      border: 1px solid #487a6f;
      box-shadow: -1px 1px 8px #bbb;
      .item_row {
        border-bottom: 1px dotted #d4d4d4;
        padding: 10px 0;
        width: 700px;
        .coltext_1 {
          color: #487a6f;
          cursor: pointer;
          font-size: 14px;
          font-weight: bold;
          display: block;
          width: 100%;
          text-align: right;
        }
        .colspan_2 {
          color: #666;
          font-size: 12px;
          border-right: 1px solid #66666670;
          padding: 0 10px;
          box-sizing: border-box;
          display: block;
          margin-bottom: 14px;
          font-weight: bold;
          cursor: pointer;
          line-height: 10px;
          &:hover {
            color: #ec7814;
            text-decoration: underline;
            font-weight: bold;
          }
          // white-space: nowrap;
          // cursor: pointer;
          // &:hover {
          //   text-decoration: #666;
          // }
        }
      }
    }
  }
}
</style>
